//axios封装
import axios from 'axios'
import {ElMessage} from "element-plus";
//@ts-ignore
import nprogress from "nprogress"


//@ts-ignore
const api = axios.create({
    baseURL:'http://localhost:8080',
    timeout: 10000
})

api.interceptors.request.use((req:any)=>{
    nprogress.start()
    let appStore=localStorage.getItem("appStore")
    req.headers.token=appStore?JSON.parse(appStore).token:null
    return req
})

api.interceptors.response.use((res:any)=>{
    nprogress.done()
    if(res.data && res.data.message) ElMessage({message: res.data.message, type: res.data.code==200?'success':'error'})
    return res.data
}, (e:any) =>{
    ElMessage.error("系统故障!");
    return Promise.reject(e)
})

export default api
